package wpspider.client.view.event;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;

import wpspider.client.model.Page;
import wpspider.client.view.ComponentRepository;

public class SearchBoxEH implements ActionListener {

	public void actionPerformed(ActionEvent event) {
		ComponentRepository repos = ComponentRepository.getInstance();		
		JComboBox searchBox = (JComboBox) repos.getComponent("searchBox");
		String word = (String) searchBox.getSelectedItem();		
		String eventCommand = event.getActionCommand();
		if ("comboBoxEdited".equals(eventCommand)) {
			if (word != null && 0 < word.length()) {
				searchBox.removeItem(word);
				int lastIndex = searchBox.getItemCount();
				if(10 < lastIndex) {
					searchBox.removeItemAt(lastIndex);					
				}
				searchBox.insertItemAt(word, 0);
			}
		} else if("comboBoxChanged".equals(eventCommand)) {
			JList pageList = (JList) repos.getComponent("pageList");
			DefaultListModel model = (DefaultListModel) pageList.getModel();
			model.removeAllElements();
			if (word != null && 0 < word.length()) {
				// Get Pages
			}
		}
	}
}
